﻿#include "PushButtonPropertyEditEntry.h"
#include <QPushButton>
#include "BooleanEditEntry.h"

#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(PushButton)

struct PushButtonPropertyEditEntry::PushButtonPropertyEditEntryPrivate {
    QPointer<QPushButton> pushButton;

    QPointer<BooleanEditEntry> entryAutoDefault;
    QPointer<BooleanEditEntry> entryDefault;
    QPointer<BooleanEditEntry> entryFlat;
};

PushButtonPropertyEditEntry::~PushButtonPropertyEditEntry() { }

PushButtonPropertyEditEntry::PushButtonPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new PushButtonPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

PushButtonPropertyEditEntry::PushButtonPropertyEditEntry(void *object, QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new PushButtonPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
    setObject(object);
}

void PushButtonPropertyEditEntry::setObject(void *object) {
    p->pushButton = static_cast<QPushButton*>(object);
}

void PushButtonPropertyEditEntry::onTick() {
    if(!p->pushButton || !isVisible()) {
        return ;
    }

    p->entryAutoDefault->setValue(p->pushButton->autoDefault());
    p->entryDefault->setValue(p->pushButton->isDefault());
    p->entryFlat->setValue(p->pushButton->isFlat());
}

void PushButtonPropertyEditEntry::initUi() {
    p->entryAutoDefault = new BooleanEditEntry;
    appendChildEntry(p->entryAutoDefault);

    p->entryDefault = new BooleanEditEntry;
    appendChildEntry(p->entryDefault);

    p->entryFlat = new BooleanEditEntry;
    appendChildEntry(p->entryFlat);
}

void PushButtonPropertyEditEntry::retranslateUi() {
    setTitle(tr("QPushButton"));
    p->entryAutoDefault->setTitle(tr("autoDefault"));
    p->entryDefault->setTitle(tr("default"));
    p->entryFlat->setTitle(tr("flat"));
}
